﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Model.SchoolKantoren;
using HROReporting.Infrastructure.UnitOfWork;
using NHibernate;
using NHibernate.Criterion;
using HROReporting.Infrastructure.Querying;

namespace HROReporting.Repository.NHibernate.Repositories
{
    public class SchoolKantoorRepository : Repository<SchoolKantoor, int>, ISchoolKantoorRepository
    {
        public SchoolKantoorRepository(IUnitOfWork uow)
            : base(uow)
        {
        }

        public SchoolKantoor GetSchoolKantoorByKantoorCode(string kantoorCode)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(SchoolKantoor))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<SchoolKantoor>
                (s => s.KantoorCode), kantoorCode));

            IList<SchoolKantoor> schoolKantoren = criteriaQuery.List<SchoolKantoor>();
            SchoolKantoor schoolKantoor = schoolKantoren.FirstOrDefault();

            return schoolKantoor;
        }
    }
}
